package com.ruoyi.utils;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.ruoyi.cinema.BO.GetEffectivePromoBO;
import com.ruoyi.cinema.DTO.*;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.order.DTO.*;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import java.util.*;

public class YzUtils {

    private static final Logger logger = LoggerFactory.getLogger(YzUtils.class);

    private static String baseUrl = "https://gw.open.yuekeyun.com/openapi/";

    /**
     * test
     */
//    private static String appSecretKey = "cVlTUl36Z6";
//    private static String channelCode = "DEMOCS_OPEN";
//    private static String channelKey = "37DF1B413B9BECF7706ADAB0E384C5E5";
//    private static String appkey = "583763";
//    private static String leaseCode = "democs";

    private static String key = "wHExDooxWHDWtfeSxvDvgqZa";

    /**
     * prod
     */
    private static String appSecretKey = "3ydz3y6d5u";
    private static String channelCode = "ZSZB_OPEN";
    private static String appkey = "749898";
    private static String leaseCode = "zszb";


    public static void main(String[] args) {
        String url = "https://h5lark.yuekeyun.com/auth/login.html";
        String code = "OC21fd0204d1b4440aa4e39c81c5985bf1";

        String refreshToken = "c38d2630bb8a40ed9ce4b1bc7a8a4b4b";
        String accessToken = "812e7e63d5eb4d44aca16ca1cff7d724";
          //getCinemaList();
        //getCinemaInfo("90234");
        //getFilmList("90007","","");
       // getFilmInfo("90007","001102452020");
         // getScheduleList("90007","","");
       // getSeatPlanList("90007","1000000122436811");
       // getAreaSeatPlanList("90007","1000000122193526");
        //getHallSeatList("90007","0000000000000002");
        //getScheduleSoldSeatList("90007","1000000122038627","","E4868A9D3806BC92C8FD230B97F4EBDC");
        //getAccessToken(refreshToken,"17889840832");
        //refreshAccessToken(refreshToken,"17889840832");
        //getToken(code);
           // getAccountInfo(accessToken);
         //getCategoryList("90007");
        //getGoodsList("90007","");
       // getGoodsInfo("90007","DP190815182155590");
        //getAccessTokenInfo(refreshToken);
        //getFulfilHallList("90007",accessToken);
        //getDeliverGoodsDateInfo("12971",null,"24f51b2f55834ced8bf8bf007f018255");
       // getCinemaGoodsPageList("90007",1,100);
//        ArrayList<GoodsYzDTO> goodsList = new ArrayList<>();
//        GoodsYzDTO goods = new GoodsYzDTO();
//        goods.setGoodsCode("HC201209170452656");
//        goods.setGoodsCount(1);
//        goodsList.add(goods);
//        getGoodsPromoList("12971", goodsList, "6c5ba888f54246d7b0738cf91d8f7b9f");
//          ArrayList<String> scaheduldId = new ArrayList<>();
//          scaheduldId.add("1000000122193526");
//          getSchedulePromoList("90007",scaheduldId);
//        List<String> openActivityTypes = new ArrayList<>(2);
//        openActivityTypes.add("DISCOUNT_TICKET");
//        openActivityTypes.add("DISCOUNT_GOODS");
//        getActivityList("2020-12-08 00:00:00","2020-12-13 23:59:59",openActivityTypes,1,100);
        //getAccessTokenInfo(refreshToken);
       // getCardList("46707746104b4bbb9d0548267b8229ef");
       // getCardInfo("88c6b7fcba0149c9a90b843e7ade6a8c","17889840832");
       // getCardListByMobile("15120603457");
        //getCardInfoByNo("01115888");
       // getCardRuleInfo("1013002");
        //getRuleList();
         //initPassword("20000475274X","12342343456","a3fd5beef1b449ea9aca9b9333bf78c0","90007");
       // getOrderInfo("12971","210117011006X129712203","db18cd9118f14f098ecec8d0a97e61e0");
       // getOrderInfoWithoutToken("12972","201230008009X129721122");
       // getFulfilHallList("12971","67d79699db5f4d628d6880d1d35a0961");
       // refundOrder("12971","210117011007X129712284","0f27e39cb1dc423684c70bc0b117955b","db18cd9118f14f098ecec8d0a97e61e0");

//        List<String> couponList = new ArrayList<>();
//        couponList.add("P3P024QK");
//        getCouponByCodeList(couponList);
        //P3P024QK
        // P3D024FK
//        GetEffectivePromoBO getEffectivePromoBO= new GetEffectivePromoBO();
//        getEffectivePromoBO.setCinemaLinkId("12971");
//        getEffectivePromoBO.setAccessToken("dfab03579a984b21bdcddf2a1be4d8c7");
//        List<EffectivePromoTicketYzDTO> ticketList = new ArrayList<>();
//        EffectivePromoTicketYzDTO ep = new EffectivePromoTicketYzDTO();
//        ep.setScheduleId("1000000129972279");
//        ep.setSeatCode("000000029429-8-9");
//        ticketList.add(ep);
//        List<EffectivePromoCouponYzDTO> couponList = new ArrayList<>();
//        EffectivePromoCouponYzDTO ec = new EffectivePromoCouponYzDTO();
//        ec.setCouponCode("P3D024FK");
//        ec.setItemType("TICKET");
//        couponList.add(ec);
//        getEffectivePromoBO.setCouponList(couponList);
//        getEffectivePromoBO.setTicketList(ticketList);
//        getEffectivePromoList(getEffectivePromoBO);

        bindingCoupon("PKBK4YXXV","7cd3992c953e4e91a4ca2ae3e54ef989");


    }



    public final static String encryptHexUseIV(String content, String secretKey){
        try {
            byte[] secretKeyBts = DigestUtils.md5(secretKey.getBytes("UTF-8"));
            return Hex.encodeHexString(encrypt(content.getBytes("UTF-8"), Arrays.copyOfRange(secretKeyBts, 0, 8), Arrays.copyOfRange(secretKeyBts, 8, 16)));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private static byte[] encrypt(byte[] content, byte[] secretKey, byte[] iv) throws Exception{
        DESKeySpec dks = new DESKeySpec(secretKey);
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        SecretKey securekey = keyFactory.generateSecret(dks);
        Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, securekey, new IvParameterSpec(iv));
        return cipher.doFinal(content);
    }

    public static String signAndRequest(String urlPath,Map<String,Object> param){
        return signAndRequest(urlPath, param,true);
    }

    public static String  signAndRequest(String urlPath,Map<String,Object> param,boolean isLog){

        param.put("_aop_timestamp",String.valueOf(System.currentTimeMillis()));
        String sign = CommonUtils.signatureWithParamsAndUrlPath(urlPath,param,appSecretKey);
        param.put("_aop_signature",sign);
        String realUrl = baseUrl+urlPath;
        String res= HttpUtil.post(realUrl, param);
        if(isLog){
            logger.info(" url : " + realUrl);
            logger.info(JSON.toJSONString(param));
            logger.info(res);
        }
        return res;
    }



    public static void getToken(String code){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.account.getAuthTokenInfo/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("code",code);
        String result = signAndRequest(urlPath, param);
    }

    public static void getAccessTokenInfo(String refreshToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.account.getAccessTokenInfo/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("refreshToken",refreshToken);
        String result = signAndRequest(urlPath, param);
    }

    /**
     * 获取isv 级别的refreshToken
     */
    public static void getRefreshToken(){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.isv.getRefreshToken/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        String result = signAndRequest(urlPath, param);
    }

    /**
     * 根据isv refreshToken 和 mobile 获取accessToken
     * @param refreshToken
     * @param mobile
     */
    public static Map<String,String> getAccessToken(String refreshToken, String mobile){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.isv.getAccessToken/"+appkey;
        Map<String, Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("refreshToken",refreshToken);
        param.put("mobile",mobile);
        String result = signAndRequest(urlPath, param);
        YzResult<Map<String,String>> accessTokenRet =  JSON.parseObject(result,new TypeReference<YzResult<Map<String,String>>>(){});
        if(null != accessTokenRet.getData() && null != accessTokenRet.getData().getBizData()){
            return accessTokenRet.getData().getBizData();
        }
        return null;
    }

    public static void refreshAccessToken(String refreshToken, String accountId){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.isv.refreshAccessToken/"+appkey;
        Map<String, Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("refreshToken",refreshToken);
        param.put("accountId",accountId);
        String result = signAndRequest(urlPath, param);
    }

    public static YzResult<AccountInfoYzDTO> getAccountInfo(String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.cif.account.getAccountInfo/"+appkey;
        Map<String, Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("access_token",accessToken);
        String result = signAndRequest(urlPath, param);
        return JSON.parseObject(result,new TypeReference<YzResult<AccountInfoYzDTO>>(){});
    }

    public static void  getPointAmountInfo(String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.cif.point.getPointAmountInfo/"+appkey;
        Map<String, Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("access_token",accessToken);
        String result = signAndRequest(urlPath, param);
    }
    /**
     * 获取渠道下的影院列表
     */
    public static YzResult<CinemaYzDTO> getCinemaList(){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.ticket.cinema.getCinemaList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        String result = signAndRequest(urlPath, param);
        return JSON.parseObject(result,new TypeReference<YzResult<CinemaYzDTO>>(){});

    }

    /**
     * 获取渠道下的影院详情
     * @param cinemaLinkId
     */
    public static YzResult<CinemaYzDTO> getCinemaInfo(String cinemaLinkId){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.ticket.cinema.getCinemaInfo/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        String result = signAndRequest(urlPath, param);
        return JSON.parseObject(result,new TypeReference<YzResult<CinemaYzDTO>>(){});
    }

    /**
     * 获取当前在放映的影片列表
     * @param cinemaLinkId
     * @param filmStartDate
     * @param filmEndDate
     */
    public static YzResult<FilmYzDTO> getFilmList(String cinemaLinkId, String filmStartDate, String filmEndDate, boolean isLog){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.ticket.film.getFilmList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        if(StringUtils.isNotEmpty(filmStartDate)){
            param.put("filmStartDate",filmStartDate);
        }
        if(!StringUtils.isNotEmpty(filmEndDate)){
            param.put("filmEndDate",filmEndDate);
        }
        String result = signAndRequest(urlPath, param,isLog);
        return JSON.parseObject(result,new TypeReference<YzResult<FilmYzDTO>>(){});
    }

    /**
     * 获取影片详情
     * @param cinemaLinkId
     * @param filmCode
     */
    public static YzResult<FilmYzDTO>  getFilmInfo(String cinemaLinkId ,String filmCode, boolean isLog){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.ticket.film.getFilmInfo/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("filmCode",filmCode);
        String result = signAndRequest(urlPath,param,isLog);
        return JSON.parseObject(result,new TypeReference<YzResult<FilmYzDTO>>(){});
    }

    /**
     * 获取排期列表
     * @param cinemaLinkId
     * @param scheduleStartDate
     * @param scheduleEndDate
     */
    public static YzResult<ScheduleYzDTO> getScheduleList(String cinemaLinkId, Date scheduleStartDate, Date scheduleEndDate, boolean isLog){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.ticket.schedule.getScheduleList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        if(null != scheduleStartDate){
            param.put("scheduleStartDate", DateUtils.parseDateToStr("yyyy-MM-dd",scheduleStartDate));
        }
        if( null != scheduleEndDate){

            param.put("scheduleEndDate",DateUtils.parseDateToStr("yyyy-MM-dd",scheduleEndDate));
        }
        String result = signAndRequest(urlPath,param,isLog);
        return JSON.parseObject(result,new TypeReference<YzResult<ScheduleYzDTO>>(){});
    }

    /**
     * 根据排期获取座位列表
     * @param cinemaLinkId
     * @param scheduleId
     */
    public static YzResult<SeatPlanYZALLDTO> getSeatPlanList(String cinemaLinkId, String scheduleId,boolean isLog){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.ticket.seat.getSeatPlanList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("scheduleId",scheduleId);
        String result = signAndRequest(urlPath,param, isLog);
        return JSON.parseObject(result,new TypeReference<YzResult<SeatPlanYZALLDTO>>(){});
    }

    /**
     * 根据排期获取区域座位列表
     * @param cinemaLinkId
     * @param scheduleId
     */
    public static YzResult<AreaSeatPlanYZALLDTO> getAreaSeatPlanList(String cinemaLinkId, String scheduleId,boolean isLog){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.ticket.seat.getAreaSeatPlanList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("scheduleId",scheduleId);
        String result = signAndRequest(urlPath,param,isLog);
        return JSON.parseObject(result,new TypeReference<YzResult<AreaSeatPlanYZALLDTO>>(){});
    }

    /**
     * 获取基础座位信息
     * @param cinemaLinkId
     * @param hallId
     */
    public static void getHallSeatList(String cinemaLinkId, String hallId){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.ticket.seat.getHallSeatList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("hallId",hallId);
        String result = signAndRequest(urlPath,param);
    }

    public static YzResult<SectionSeatSoldDTO> getScheduleSoldSeatList(String cinemaLinkId, String scheduleId, String sectionCode, String scheduleKey){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.seat.getScheduleSoldSeatList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("scheduleId",scheduleId);
        if(StringUtils.isNotEmpty(sectionCode)){
            param.put("sectionCode",sectionCode);
        }
        param.put("scheduleKey",scheduleKey);
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<SectionSeatSoldDTO>>(){});
    }

    public static YzResult<LockSeatRetDTO> lockSeat(String cinemaLinkId, String scheduleId, String scheduleKey, String outId, List<String> seatCodeList, String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.seat.lockSeat/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("scheduleKey",scheduleKey);
        param.put("scheduleId",scheduleId);
        param.put("outId",outId);
        param.put("seatCodeList",JSON.toJSONString(seatCodeList));
        param.put("access_token",accessToken);
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<LockSeatRetDTO>>(){});

    }

    public static YzResult<String> unlockSeat(String cinemaLinkId, String lockOrderId, String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.seat.unlockSeat/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("lockOrderId",lockOrderId);
        param.put("access_token",accessToken);
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<String>>(){});
    }


    public static YzResult<CategoryYzDTO> getCategoryList(String cinemaLinkId){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.item.goods.getCategoryList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("cinemaLinkId",cinemaLinkId);
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<CategoryYzDTO>>(){});

    }

    public static YzResult<GoodsInfoALLYzDTO> getGoodsList(String cinemaLinkId, String categoryCode,boolean isLog){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.item.goods.getGoodsList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        if(StringUtils.isNotEmpty(categoryCode)){
            param.put("categoryCode",categoryCode);
        }
        String result = signAndRequest(urlPath,param, isLog);
        return JSON.parseObject(result,new TypeReference<YzResult<GoodsInfoALLYzDTO>>(){});

    }

    public static void getGoodsInfo(String cinemaLinkId, String goodsCode) {
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.item.goods.getGoodsInfo/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("goodsCode", goodsCode);
        String result = signAndRequest(urlPath,param);
    }

    public static YzResult<HallYzDTO> getFulfilHallList(String cinemaLinkId, String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.fulfil.getFulfilHallList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("access_token",accessToken);
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<HallYzDTO>>(){});
    }

    public static YzResult<DeliverGoodsRetYzDTO> getDeliverGoodsDateInfo(String cinemaLinkId, String hallCode, String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.fulfil.getDeliverGoodsDateInfo/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        if(StringUtils.isNotEmpty(hallCode)){
            param.put("hallCode",hallCode);
        }
        param.put("access_token",accessToken);
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<DeliverGoodsRetYzDTO>>(){});
    }

    public static void getCinemaGoodsPageList(String cinemaLinkId, Integer pageNo, Integer pageSize){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.item.goods.getCinemaGoodsPageList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("pageNo",pageNo);
        param.put("pageSize",pageSize);
        String result = signAndRequest(urlPath,param);

    }

    public static YzResult<GoodsPromoRetYzDTO> getGoodsPromoList(String cinemaLinkId, List<GoodsYzDTO> goodsList, String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.promo.getGoodsPromoList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("goodsList",JSON.toJSONString(goodsList));
        if(StringUtils.isNotEmpty(accessToken)){
            param.put("access_token",accessToken);
        }
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<GoodsPromoRetYzDTO>>(){});
    }

    public static YzResult<SchedulePromoYzDTO> getSchedulePromoList(String cinemaLinkId, List<String> scheduleIdList, String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.promo.getSchedulePromoList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        if(!StringUtils.isEmpty(cinemaLinkId)){
            param.put("cinemaLinkId",cinemaLinkId);
        }
        param.put("scheduleIdList",JSON.toJSONString(scheduleIdList));
        param.put("access_token", accessToken);
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<SchedulePromoYzDTO>>(){});

    }

    public static YzResult<SchedulePromoYzDTO> getSeatMapPromoList(String accessToken, String cinemaLinkId, String scheduleId){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.promo.getSeatMapPromoList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("access_token",accessToken);
        param.put("scheduleId",scheduleId);
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<SchedulePromoYzDTO>>(){});
    }

    public static YzResult<EffectivePromoAllYzDTO> getEffectivePromoList(GetEffectivePromoBO gepb){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.promo.getEffectivePromoList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("cinemaLinkId",gepb.getCinemaLinkId());
        param.put("promoTypeList",JSON.toJSONString(gepb.getPromoTypeList()));
        if(null != gepb.getTicketList() && !gepb.getTicketList().isEmpty()){
            param.put("ticketList",JSON.toJSONString(gepb.getTicketList()));
        }
        if(null != gepb.getGoodsList() && !gepb.getGoodsList().isEmpty()){
            param.put("goodsList",JSON.toJSONString(gepb.getGoodsList()));
        }
        if(null != gepb.getCouponList() && !gepb.getCouponList().isEmpty()){
            param.put("couponList",JSON.toJSONString(gepb.getCouponList()));
        }

        param.put("access_token",gepb.getAccessToken());
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<EffectivePromoAllYzDTO>>(){});
    }

    public static YzResult<ConfirmTicketRetYzDTO> confirmTicketOrder(ConfirmTicketOrderYzDTO confirmTicketOrderYzDTO , String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.order.confirmTicketOrder/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("access_token",accessToken);
        param.put("mobile",confirmTicketOrderYzDTO.getMobile());
        param.put("cinemaLinkId",confirmTicketOrderYzDTO.getCinemaLinkId());
        param.put("scheduleId",confirmTicketOrderYzDTO.getScheduleId());
        param.put("scheduleKey",confirmTicketOrderYzDTO.getScheduleKey());
        param.put("lockOrderId",confirmTicketOrderYzDTO.getLockOrderId());
        param.put("orderAmount",confirmTicketOrderYzDTO.getOrderAmount());
        param.put("payAmount",confirmTicketOrderYzDTO.getPayAmount());
        param.put("promoAmount",confirmTicketOrderYzDTO.getPromoAmount());
        param.put("ticketList",JSON.toJSONString(confirmTicketOrderYzDTO.getTicketList()));
        param.put("paymentList",JSON.toJSONString(confirmTicketOrderYzDTO.getPaymentList()));
        if(null == confirmTicketOrderYzDTO.getPromotionList()){
            confirmTicketOrderYzDTO.setPromotionList(new ArrayList<>());
        }
        param.put("promotionList",JSON.toJSONString(confirmTicketOrderYzDTO.getPromotionList()));

        String result = signAndRequest(urlPath,param);

        return JSON.parseObject(result,new TypeReference<YzResult<ConfirmTicketRetYzDTO>>(){});
    }

    public static YzResult<ConfirmTicketRetYzDTO> confirmGoodsOrder(ConfirmGoodsOrderYzDTO confirmGoodsOrderYzDTO , String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.order.confirmGoodsOrder/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("access_token",accessToken);
        param.put("mobile",confirmGoodsOrderYzDTO.getMobile());
        param.put("outId",confirmGoodsOrderYzDTO.getOutId());
        param.put("cinemaLinkId",confirmGoodsOrderYzDTO.getCinemaLinkId());
        param.put("orderAmount",confirmGoodsOrderYzDTO.getOrderAmount());
        param.put("payAmount",confirmGoodsOrderYzDTO.getPayAmount());
        param.put("promoAmount",confirmGoodsOrderYzDTO.getPromoAmount());
        param.put("goodsList",JSON.toJSONString(confirmGoodsOrderYzDTO.getGoodsList()));
        param.put("paymentList",JSON.toJSONString(confirmGoodsOrderYzDTO.getPaymentList()));
        if(null == confirmGoodsOrderYzDTO.getPromotionList()){
            confirmGoodsOrderYzDTO.setPromotionList(new ArrayList<>());
        }
        param.put("promotionList",JSON.toJSONString(confirmGoodsOrderYzDTO.getPromotionList()));
        if(null != confirmGoodsOrderYzDTO.getFulfillInfo()){
            param.put("fulfillInfo",JSON.toJSONString(confirmGoodsOrderYzDTO.getFulfillInfo()));
        }
        String result = signAndRequest(urlPath,param);

        return JSON.parseObject(result, new TypeReference<YzResult<ConfirmTicketRetYzDTO>>(){});
    }

    public static YzResult<RefundOrderYzDTO> refundOrder(String cinemaLinkId, String orderId, String outId, String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.order.refundOrder/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("access_token",accessToken);
        param.put("orderId",orderId);
        param.put("outId",outId);
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<RefundOrderYzDTO>>(){});
    }

    public static YzResult<OrderInfoYzDTO> getOrderInfo(String cinemaLinkId , String orderId, String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.order.getOrderInfo/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("access_token",accessToken);
        param.put("orderId",orderId);
        String result = signAndRequest(urlPath,param);

        return JSON.parseObject(result,new TypeReference<YzResult<OrderInfoYzDTO>>(){});
    }

    public static YzResult<OrderInfoYzDTO> getOrderInfoWithoutToken(String cinemaLinkId ,String orderId){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.report.order.getOrderInfo/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("cinemaLinkId",cinemaLinkId);
        param.put("orderId",orderId);
        String result = signAndRequest(urlPath,param);

        return JSON.parseObject(result,new TypeReference<YzResult<OrderInfoYzDTO>>(){});
    }

    public static String getOrderList(String accessToken,Integer pageNo, Integer pageSize){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.order.getOrderList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("access_token",accessToken);
        param.put("pageNo",pageNo);
        param.put("pageSize",pageSize);
        return signAndRequest(urlPath,param);
    }

    public static YzResult<CardInfoYzDTO> getCardList(String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.card.account.getCardList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("access_token",accessToken);
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result,new TypeReference<YzResult<CardInfoYzDTO>>(){});

    }

    public static YzResult<CardInfoYzDTO> getCardInfo(String accessToken , String cardNo){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.card.account.getCardInfo/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("access_token",accessToken);
        param.put("cardNo",cardNo);
        String result = signAndRequest(urlPath,param);
        return JSON.parseObject(result, new TypeReference<YzResult<CardInfoYzDTO>>(){});
    }

    public static String getCardListByMobile(String mobile){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.card.base.getCardListByMobile/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("mobile",mobile);
        return signAndRequest(urlPath,param);

    }

    public static String getCardInfoByNo(String cardNo){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.card.base.getCardInfoByNo/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("cardNo",cardNo);
        return signAndRequest(urlPath,param);

    }

    public static YzResult<CardRuleInfoYzDTO> getCardRuleInfo(String cardRuleId){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.card.rule.getRuleInfo/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("cardRuleId",cardRuleId);
        String res = signAndRequest(urlPath,param);
        YzResult<CardRuleInfoYzDTO> yzDTOYzResult = JSON.parseObject(res,new TypeReference<YzResult<CardRuleInfoYzDTO>>(){});
        return yzDTOYzResult;
    }

    public static String getRuleList(){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.card.rule.getRuleList/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        return signAndRequest(urlPath,param);
    }

    public static String confirmCardOrder(Map<String,Object> param){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.order.confirmCardOrder/"+appkey;

        param.put("cardInfo",JSON.toJSONString(param.get("cardInfo")));
        param.put("paymentList",JSON.toJSONString(param.get("paymentList")));
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        return signAndRequest(urlPath,param);
    }

    public static YzResult<ConfirmTicketRetYzDTO> confirmRechargeOrder(ConfirmRechargeOrderYzDTO confirmRechargeOrderYzDTO, String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.order.confirmRechargeOrder/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("cinemaLinkId",confirmRechargeOrderYzDTO.getCinemaLinkId());
        param.put("outId",confirmRechargeOrderYzDTO.getOutId());
        param.put("orderAmount",confirmRechargeOrderYzDTO.getOrderAmount());
        param.put("payAmount",confirmRechargeOrderYzDTO.getPayAmount());
        param.put("cardInfo",JSON.toJSONString(confirmRechargeOrderYzDTO.getCardInfoYzDTO()));
        param.put("paymentList",JSON.toJSONString(confirmRechargeOrderYzDTO.getPaymentList()));
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("access_token",accessToken);
        String result = signAndRequest(urlPath,param);
        return  JSON.parseObject(result,new TypeReference<YzResult<ConfirmTicketRetYzDTO>>(){});
    }

    public static YzResult<ConfirmTicketRetYzDTO> confirmExtensionFeeOrder(ConfirmExtensionFeeOrderYzDTO confirmExtensionFeeOrderYzDTO, String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.own.order.confirmExtensionFeeOrder/"+appkey;
        Map<String,Object> param = new HashMap<>();
        param.put("cinemaLinkId",confirmExtensionFeeOrderYzDTO.getCinemaLinkId());
        param.put("outOrderId",confirmExtensionFeeOrderYzDTO.getOutOrderId());
        param.put("orderAmount",confirmExtensionFeeOrderYzDTO.getOrderAmount());
        param.put("payAmount",confirmExtensionFeeOrderYzDTO.getPayAmount());
        param.put("cardNo",confirmExtensionFeeOrderYzDTO.getCardNo());
        param.put("membershipFee",confirmExtensionFeeOrderYzDTO.getMembershipFee());
        param.put("paymentList",JSON.toJSONString(confirmExtensionFeeOrderYzDTO.getPaymentList()));
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("access_token",accessToken);
        String result = signAndRequest(urlPath,param);
        return  JSON.parseObject(result,new TypeReference<YzResult<ConfirmTicketRetYzDTO>>(){});
    }


    public static String  initPassword(String cardNo,String cardPassword,String accessToken,String cinemaLinkId){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.card.password.initPassword/"+appkey;

        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("cardNo",cardNo);
        param.put("cardPassword", encryptHexUseIV(cardPassword,key));
        param.put("access_token",accessToken);
        param.put("cinemaLinkId",cinemaLinkId);
        return signAndRequest(urlPath,param);
    }

    public static String getCouponByCodeList(List<String> couponCodeList){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.coupon.base.getCouponByCodeList/"+appkey;

        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("couponCodeList",JSON.toJSONString(couponCodeList));
        return signAndRequest(urlPath,param);
    }

    public static YzResult<String> bindingCoupon(String couponCode, String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.coupon.account.bindingCoupon/"+appkey;

        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("access_token",accessToken);
        param.put("couponCode",couponCode);
        String result = signAndRequest(urlPath,param);
        return  JSON.parseObject(result,new TypeReference<YzResult<String>>(){});
    }

    public static YzResult<CouponInfoYzDTO> getCouponPageList(Integer pageNo, Integer pageSize,String accessToken){
        String urlPath = "param2/1/alibaba.dme.lark/dme.lark.coupon.account.getCouponPageList/"+appkey;

        Map<String,Object> param = new HashMap<>();
        param.put("channelCode",channelCode);
        param.put("leaseCode",leaseCode);
        param.put("access_token",accessToken);
        param.put("pageNo",pageNo);
        param.put("pageSize", pageSize);
        String result = signAndRequest(urlPath,param);
        return  JSON.parseObject(result,new TypeReference<YzResult<CouponInfoYzDTO>>(){});
    }


}
